<?php

namespace App\Http\Controllers;

use App\Article;
use Illuminate\Http\Request;



class ArticleController extends Controller
{

/**
 * @OA\Info(
 *     version="1.0",
 *     title="Example for response examples value3424"
 * )
 */

/**
 * @OA\Get(
 *     path="/article",
 *     @OA\Response(response="200", description="An example resource")
 * )
 */
    public function index()
    {
        //
        $articles = Article::all();
        return $articles;
    }


/**
 * @OA\Post(
 *     path="/article",
 *     summary="Adds a new user",
 *     @OA\RequestBody(
 *         @OA\MediaType(
 *             mediaType="application/json",
 *             @OA\Schema(
 *                 @OA\Property(
 *                     property="title",
 *                     type="string"
 *                 ),
 *                 @OA\Property(
 *                     property="content",
 *                     type="string"
 *                 ),
 *                 example={"title": "a3fb6", "content": "Jessica Smith"}
 *             )
 *         )
 *     ),
 *     @OA\Response(
 *         response=200,
 *         description="OK"
 *     )
 * )
 */
    public function store(Request $request)
    {
        //
        $input = $request->all();
        $user = Article::create($input);
        if($user) {
          return '1';
        } else {
          return '0';        
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
        $article = Article::find($id);
        return $article;
    }

    /**
     * 改
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
        $content = $request->input('content');
        $title = $request->input('title');
        
        $flight = Article::find($id);
        $flight->content = $content;
        $flight->title = $title;
        $isres = $flight->save();
        return $isres;
    }

    /**
     * 删
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
        $flight = Article::find($id);
        $isres = $flight->delete();
        return $isres;
    }
}
